#include "wxsfontdialog.h"
#include "../wxsitemresdata.h"
#include <wx/fontdlg.h>

namespace {
  wxsRegisterItem<wxsFontDialog> Reg( _T( "FontDialog" ), _T( "FontDialog" ), wxsTTool, _T( "对话框" ), 160, false );
}


wxsFontDialog::wxsFontDialog( wxsItemResData* Data ):
  wxsTool( Data, &Reg.Info ),
  m_bAllowSymbols( true ),
  m_bEnableEffects( true ),
  m_bShowHelp( false ),
  m_iMinSize( 0 ),
  m_iMaxSize( 0 ) {
}


void wxsFontDialog::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
    case wxsCPP: {
      AddHeader( _T( "<wx/fontdlg.h>" ), GetInfo().ClassName, hfInPCH );
      wxString sfontName = GetCoderContext()->GetUniqueName( _T( "fontData" ) );
      Codef( _T( "\twxFontData %s;\n" ), sfontName.wx_str() );
      wxString sClr = m_cdColour.BuildCode( GetCoderContext() );
      if( !sClr.IsEmpty() ) {
        Codef( _T( "\t%s.SetColour(%s);\n" ), sfontName.wx_str(), sClr.wx_str() );
      }
      if( !m_bEnableEffects ) {
        Codef( _T( "\t%s.EnableEffects(%b);\n" ), sfontName.wx_str(), m_bEnableEffects );
      }
      Codef( _T( "\t%s.SetInitialFont(*wxNORMAL_FONT);\n" ), sfontName.wx_str() );
      if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
        if( !m_bShowHelp ) {
          Codef( _T( "\t%s.SetAllowSymbols(%b);\n" ), sfontName.wx_str(), m_bAllowSymbols );
        }
        if( m_iMinSize > 0 || m_iMaxSize > 0 ) {
          Codef( _T( "\t%s.SetRange(%d, %d);\n" ), sfontName.wx_str(), m_iMinSize, m_iMaxSize );
        }
        if( m_bShowHelp ) {
          Codef( _T( "\t%s.SetShowHelp(%b);\n" ), sfontName.wx_str(), m_bShowHelp );
        }
      }
      Codef( _T( "%C(%W, %s);\n" ), sfontName.wx_str() );
      BuildSetupWindowCode();
      return;
    }
    case wxsUnknownLanguage:
    default: {
      wxsCodeMarks::Unknown( _T( "wxsFontDialog::OnBuildCreatingCode" ), GetLanguage() );
    }
  }
}


void wxsFontDialog::OnEnumToolProperties( M_Code_unused long Flags ) {
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    WXS_BOOL( wxsFontDialog, m_bAllowSymbols, _T( "Allow Symbols" ), _T( "allow_symbols" ), true )
  }
  WXS_COLOUR( wxsFontDialog, m_cdColour, _T( "Colour" ), _T( "colour" ) );
  WXS_BOOL( wxsFontDialog, m_bEnableEffects, _T( "Enable Effects" ), _T( "enable_effects" ), true )
  if( ( wxPlatformInfo::Get().GetOperatingSystemId() & wxOS_WINDOWS ) > 0 ) {
    WXS_LONG( wxsFontDialog, m_iMinSize,  _T( "Min. Size" ), _T( "min_size" ), 0 )
    WXS_LONG( wxsFontDialog, m_iMaxSize,  _T( "Max. Size" ), _T( "max_size" ), 0 )
    WXS_BOOL( wxsFontDialog, m_bShowHelp, _T( "Show Help" ), _T( "show_help" ), false )
  }
}
